package org.tigr.htc.server;

/*
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

import org.tigr.antware.shared.util.Logger;
import org.tigr.htc.common.HTCConfig;
import org.tigr.htc.server.condor.CondorGridStatusUtils;
import org.tigr.htc.server.sge.SgeGridStatusUtils;

/**
 * The class <code>GridStatusUtilsFactory</code> is used to return the grid status utils class for the
 * current grid implementation. This class is a factory class and reads the grid type from the HTC config
 * file to decide which type of class to instantiate and return.
 * 
 */

public class GridStatusUtilsFactory {
    /**
     * The variable <code>logger</code> holds the instance of the logger for this class.
     */
    private static Logger logger = new Logger(GridStatusUtilsFactory.class.getCanonicalName());
    
    private static IGridStatusUtils statusUtils;
    
    /**
     * The method <code>getStatusUtils</code> method returns the instance of the IGridStatusUtils
     * class that provides the methods to monitor the grid status.
     * 
     * @return a <code>IGridStatusUtils</code> based on the grid type specified in the config file
     */
    public static IGridStatusUtils getStatusUtils () {
        if (statusUtils == null) {
            String gridType = HTCConfig.getProperty("grid.type");
            if (logger.isDebugEnabled()) {
                logger.debug("Creating a new status utils class for grid type: " + gridType );
                if (gridType.equals(JobMonitorFactory.SGE)) {
                    statusUtils = new SgeGridStatusUtils();
                } else if (gridType.equals(JobMonitorFactory.CONDOR)) {
                	statusUtils = new CondorGridStatusUtils();
                }
            }
        }
        return statusUtils;
    }

}
